package com.homson.coreservice.serviceinfrastructure.converter;

import com.homson.coreservice.servicecommon.enumeration.AccountTypeEnum;
import com.homson.coreservice.serviceinfrastructure.dto.AccountDto;
import com.homson.coreservice.serviceinfrastructure.datasource.model.account.AccountDO;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;

/**
 * @author: homson_leo
 * @contact: hey_超级巨星（Homson_Leo）- 刘泓岑 1196816884@qq.com
 * @time: 2025/11/15 3:31 PM
 **/
public class AccountConverter {
    
    public static List<AccountDto> convert(List<AccountDO> accountDOs) {
        if(CollectionUtils.isEmpty(accountDOs)){
            return Collections.emptyList();
        }
        List<AccountDto> accountDtos = accountDOs.stream().map(accountDO -> {
            AccountDto accountDto = new AccountDto();
            accountDto.setAccountId(accountDO.getAccountId());
            accountDto.setAccountName(accountDO.getName());
            accountDto.setAccountType(AccountTypeEnum.valueOf(accountDO.getType()));
            accountDto.setBalance(accountDO.getBalance());
            accountDto.setUpdateTime(accountDO.getUpdatedAt());
            return accountDto;
        }).toList();
        return accountDtos;
    }
}
